package com.feng.controller.back;

import com.feng.dto.ProductDto;
import com.feng.service.ProductService;
import com.feng.vo.PageVo;
import com.feng.vo.ProductVo;
import com.feng.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 丰
 * @date: 2022/12/30 10:05
 */
@RestController
@RequestMapping("/back/product")
@Api(tags = "后台产品接口")
public class ProductController {

    @Autowired
    private ProductService productService;

    @GetMapping("/getList")
    @ApiOperation("条件分页查询")
    public ResultVo<List<ProductDto>> getList(PageVo pageVo){
        return productService.selectAll(pageVo);
    }

    @ApiOperation("添加")
    @PutMapping("/add")
    public ResultVo<Integer> add(@RequestBody ProductVo productVo){
        return productService.add(productVo);
    }

    @ApiOperation("批量删除")
    @DeleteMapping("/deleteAll")
    public ResultVo<Integer> deleteAll(@RequestBody Integer[] ids){
        return productService.deleteAll(ids);
    }

    @ApiOperation("根据id删除")
    @DeleteMapping("/delete/{id}")
    public ResultVo<Integer> delete(@PathVariable("id") Integer id){
        return productService.deleteById(id);
    }

    @ApiOperation("更新是否可用")
    @PostMapping("/enable")
    public ResultVo<Integer> enable(@RequestBody ProductVo productVo){
        return productService.modifyEnable(productVo);
    }

    @ApiOperation("通过id查询")
    @GetMapping("/findById/{id}")
    public ResultVo<ProductDto> findById(@PathVariable("id") Integer id){
        return productService.findById(id);
    }

    @ApiOperation("更新")
    @PostMapping("/update")
    public ResultVo<Integer> update(@RequestBody ProductVo productVo){
        return productService.update(productVo);
    }
}
